
// pages/extrasDetail/extrasDetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isCollection: false,
    collectionText: '收藏',
    toSee: false,
    isAuthentication: true,
    isPerfect: true,
    info: {},
    isCollection: false,
    content: '',
  },

  // 收藏
  collection: function () {
    let w_collect = `${this.data.info.w_collect}`
    app.post('Member/collectWork', {
      workId: this.data.info.w_id,
      token: wx.getStorageSync('token')
    }).then(res => {
      wx.showToast({
        title: res.data.result_code == 100 ? '收藏成功' : '取消成功',
      })
      this.setData({
        isCollection: res.data.result_code == 100 ? true : false,
      })
    })
  },

  // 查看营业执照
  see: function () {
    this.setData({
      toSee: !this.data.toSee
    })
  },

  noMove: function () {
    return false
  },

  // 去实名认证
  toAuthentication: function () {
    wx.navigateTo({
      url: '/pages/realName/realName',
    })
  },

  // 去完善简历
  perfect: function () {
    wx.navigateTo({
      url: '/pages/releaseResume/releaseResume',
    })
  },

  // 投递简历
  delivery: function (e) {
    app.post('Work/delivery', {
      token: wx.getStorageSync('token'),
      workId: e.currentTarget.dataset.wid
    }).then(res => {
      let code = res.data.result_code
      wx.showModal({
        title: '提示',
        content: res.data.result_message,
        showCancel: false,
        success: res => {
          if (res.confirm) {
            if (code == 101) {
              this.toAuthentication()
            } else if (code == 103) {
              this.perfect()
            } else {
              wx.navigateTo({
                url: '/pages/myResume/myResume',
              })
            }
          }
        }
      })
    })
  },

  // 咨询内容
  content: function (e) {
    this.data.content = e.detail.value
  },

  // 咨询
  service: function (e) {
    this.setData({
      isService: true
    })
  },

  // 咨询提交
  contentSubmit: function () {
    if (this.data.content == '') {
      wx.showToast({
        title: '请填写内容',
        icon: 'none'
      })
    } else {
      app.post('Member/send', {
        token: wx.getStorageSync('token'),
        detail: this.data.content,
        receive: this.data.info.m_id
      }).then(() => {
        this.setData({
          isService: false
        })
      })
    }
  },

  // 取消
  cancel: function() {
    this.setData({
      isService: false
    })
  },

  // 分享
  share: function (e) {

  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.showLoading({
      title: '正在加载...',
    })
    app.post('Index/workDetail', {
      id: options.wid,
      token: wx.getStorageSync('token')
    }).then(res => {
      let info = res.data.result_data
      info.result_evaluate = res.data.result_evaluate
      that.setData({
        info,
        isCollection: info.w_collect
      })
      wx.hideLoading()
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})